/*
	File: data/scripts/scene_physics-get-measures.nut
	Author: GameStart3d.com
*/

/*!
	@short	ScenePhysicsGetMeasures
	@author	GameStart3d.com
*/
class	ScenePhysicsGetMeasures
{
	itemA			=	0		
	itemB			=	0
	debug_vector	=	0
	force			=	0
	linear_vel		=	0
	linear_acc		=	0
	prev_linear_vel	=	0
	label			=	0

	/*!
		@short	OnRenderUser
		Debug informations.
	*/
	function	OnRenderUser(scene)
	{
		RendererSetIdentityWorldMatrix(g_render)

		foreach(vec in debug_vector)
			RendererDrawLine(g_render, vec.A, vec.B)

		debug_vector = []		
	}

	/*!
		@short	OnUpdate
		Called each frame.
	*/
	function	OnUpdate(scene)
	{
		prev_linear_vel = clone(linear_vel)
		linear_vel = ItemGetLinearVelocity(itemA)
		linear_acc = ItemGetLinearAcceleration(itemA)

		local	str = ""
		str += "ItemGetLinearVelocity() = " + linear_vel.Len() + "\n"
		str += "ItemGetLinearAcceleration() = " + linear_acc.Len() + "\n"
		str += "Velocity - Prev.Vel = " + (linear_vel.Len() - prev_linear_vel.Len())
		label.label = str

		force = (ItemGetMatrix(itemA).GetDown() + ItemGetMatrix(itemA).GetFront()).Normalize()
		ItemApplyLinearImpulse(itemA, force.Scale(0.2))

		debug_vector.append({A = ItemGetPosition(itemA), B = ItemGetPosition(itemB)})
		debug_vector.append({A = ItemGetPosition(itemA), B = ItemGetPosition(itemA) + force.Scale(2.0)})
	}

	/*!
		@short	OnSetup
		Called when the scene is about to be setup.
	*/
	function	OnSetup(scene)
	{
		debug_vector = []

		itemA = SceneFindItem(scene, "SolidA")
		itemB = SceneFindItem(scene, "SolidB")

		SceneAddPointConstraint(scene, "const0", itemA, itemB, Vector(0,1.5,0), Vector(0,-1.5,0))
		force = g_zero_vector
		linear_vel = g_zero_vector
		linear_acc = g_zero_vector
		prev_linear_vel = g_zero_vector
		label = ItemGetScriptInstance(itemB)
	}
}

